package com.liming.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.liming.domain.BuyCar;
import com.liming.domain.User;
import com.liming.service.impl.BookServiceImpl;
import com.liming.utils.DBUtils;

public class ChangeNumServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			String id=request.getParameter("id");
			String num=request.getParameter("num");
			BuyCar buycar=(BuyCar) request.getSession().getAttribute("buycar");
			BookServiceImpl service=new BookServiceImpl();
			service.changeItemNum(id,num,buycar);
			User user=(User)request.getSession().getAttribute("user");
			if(user!=null){
				
				String sql="update Pickbooks set pick_num="+Integer.parseInt(num)+"where U_username=\'"+user.getUsername()+"\' and B_id="+id;
				System.out.println(sql);
				DBUtils.modify(sql);
			}
			response.sendRedirect(request.getContextPath()+"/servlet/BuyCarfoUI");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);

	}

}
